clear all
capture log close
capture set virtual off
set memory 1000m
capture set matsize 100000000000
capture set more off
capture virtual off
memory

set type double
set more off
set maxvar 32767
pause on
version 12.1

cd "/Users/Mandywu/Dropbox (MIT)/PNAS revision/code"

****************** code for table S1
use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 0
eststo: regress treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 1
eststo: regress treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 2
eststo: regress treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 3
eststo: regress treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 4
eststo: regress treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

esttab using tableS1_1.tex, se r2 replace
eststo clear




use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 0
eststo: logit treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 1
eststo: logit treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 2
eststo: logit treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 3
eststo: logit treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

use logit_city1, replace
gen treated = 1
replace  treated = 0 if campaign_round != 4
eststo: logit treated per_capita_log pop_density_log investment_log electricity_log ///
so2_emission_log dust_emission_log city_so2_0to4wk_diff city_so2_5to10wk_diff

esttab using tableS1_2.tex, se pr2 replace
eststo clear



****************** code for table S2
******** t-test for first round
eststo clear

use logit_all1, replace
keep if province == "河南省" | province == "黑龙江省" | province == "广东省" | province=="湖北省"
gen treated = 1
replace  treated = 0 if ( province != "河南省" & province !="黑龙江省" )
eststo: estpost ttest per_capita_log pop_density_log investment_log electricity_log so2_emission_log dust_emission_log ///
city_km_log kgsj_log lr_cityshare state_upper state_lower plant_so2_0to4wk plant_so2_5to10wk, by(treated)

******** t-test for second round
use logit_all1, replace
keep if province == "广东省" | province=="湖北省" | province == "山西省" | province =="湖南省"
gen treated = 1
replace  treated = 0 if ( province != "湖北省" &  province != "广东省" )
eststo: estpost ttest per_capita_log pop_density_log investment_log electricity_log so2_emission_log dust_emission_log ///
city_km_log kgsj_log lr_cityshare state_upper state_lower plant_so2_0to4wk plant_so2_5to10wk, by(treated)

******** t-test for third round
use logit_all1, replace
keep if province == "山西省" | province =="湖南省" | province == "山东省" | province=="浙江省"
gen treated = 1
replace  treated = 0 if ( province != "山西省" & province != "湖南省" )
eststo: estpost ttest per_capita_log pop_density_log investment_log electricity_log so2_emission_log dust_emission_log ///
city_km_log kgsj_log lr_cityshare state_upper state_lower plant_so2_0to4wk plant_so2_5to10wk, by(treated)

esttab using tableS2.tex, se ar2 replace
eststo clear


capt prog drop appendmodels
program appendmodels, eclass
    
    version 8
    syntax namelist
    tempname b V tmp
    foreach name of local namelist {
        qui est restore `name'
        mat `tmp' = e(b)
        local eq1: coleq `tmp'
        gettoken eq1 : eq1
        mat `tmp' = `tmp'[1,"`eq1':"]
        local cons = colnumb(`tmp',"_cons")
        if `cons'<. & `cons'>1 {
            mat `tmp' = `tmp'[1,1..`cons'-1]
        }
        mat `b' = nullmat(`b') , `tmp'
        mat `tmp' = e(V)
        mat `tmp' = `tmp'["`eq1':","`eq1':"]
        if `cons'<. & `cons'>1 {
            mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
        }
        capt confirm matrix `V'
        if _rc {
            mat `V' = `tmp'
        }
        else {
            mat `V' = ///
            ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
            ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
        }
    }
    local names: colfullnames `b'
    mat coln `V' = `names'
    mat rown `V' = `names'
    eret post `b' `V'
    eret local cmd "whatever"
end



***************** code for table S3
eststo clear

use paired_henan_heilongjiang_eb_nt, replace
gen campaign_round = 0
replace campaign_round = 1 if ( province == "河南省" | province =="黑龙江省" )
replace campaign_round = 2 if ( province == "湖北省" |  province == "广东省" )
replace campaign_round = 3 if ( province == "山西省" | province == "湖南省" )
replace campaign_round = 4 if ( province == "山东省" |  province == "浙江省" )
svyset [pweight=_webal]
eststo b1: svy: regress treated per_capita_log
eststo b2: svy: regress treated pop_density_log
eststo b3: svy: regress treated investment_log
eststo b4: svy: regress treated electricity_log
eststo b5: svy: regress treated so2_emission_log
eststo b6: svy: regress treated dust_emission_log
eststo b7: svy: regress treated city_km_log
eststo b8: svy: regress treated kgsj_log
eststo b9: svy: regress treated lr_cityshare
eststo b10: svy: regress treated state_upper
eststo b11: svy: regress treated state_lower
eststo b12: svy: regress treated plant_so2_0to4wk
eststo b13: svy: regress treated plant_so2_5to10wk
eststo bivar1: appendmodels b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13

use paired_hubei_guangdong_eb_nt, replace
gen campaign_round = 0
replace campaign_round = 1 if ( province == "河南省" | province =="黑龙江省" )
replace campaign_round = 2 if ( province == "湖北省" |  province == "广东省" )
replace campaign_round = 3 if ( province == "山西省" | province == "湖南省" )
replace campaign_round = 4 if ( province == "山东省" |  province == "浙江省" )
svyset [pweight=_webal]
eststo b1: svy: regress treated per_capita_log
eststo b2: svy: regress treated pop_density_log
eststo b3: svy: regress treated investment_log
eststo b4: svy: regress treated electricity_log
eststo b5: svy: regress treated so2_emission_log
eststo b6: svy: regress treated dust_emission_log
eststo b7: svy: regress treated city_km_log
eststo b8: svy: regress treated kgsj_log
eststo b9: svy: regress treated lr_cityshare
eststo b10: svy: regress treated state_upper
eststo b11: svy: regress treated state_lower
eststo b12: svy: regress treated plant_so2_0to4wk
eststo b13: svy: regress treated plant_so2_5to10wk
eststo bivar2: appendmodels b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13

use paired_shanxi_hunan_eb_nt, replace
gen campaign_round = 0
replace campaign_round = 1 if ( province == "河南省" | province =="黑龙江省" )
replace campaign_round = 2 if ( province == "湖北省" |  province == "广东省" )
replace campaign_round = 3 if ( province == "山西省" | province == "湖南省" )
replace campaign_round = 4 if ( province == "山东省" |  province == "浙江省" )
svyset [pweight=_webal]
eststo b1: svy: regress treated per_capita_log
eststo b2: svy: regress treated pop_density_log
eststo b3: svy: regress treated investment_log
eststo b4: svy: regress treated electricity_log
eststo b5: svy: regress treated so2_emission_log
eststo b6: svy: regress treated dust_emission_log
eststo b7: svy: regress treated city_km_log
eststo b8: svy: regress treated kgsj_log
eststo b9: svy: regress treated lr_cityshare
eststo b10: svy: regress treated state_upper
eststo b11: svy: regress treated state_lower
eststo b12: svy: regress treated plant_so2_0to4wk
eststo b13: svy: regress treated plant_so2_5to10wk
eststo bivar3: appendmodels b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13

esttab bivar1 bivar2 bivar3 using tableS3.tex, replace



***** table event_nt
use campaign_all_10wk_nt, replace
loc minbalancedeventtime = -10
loc maxbalancedeventtime = 10

forval v = `minbalancedeventtime'/-1 {
loc absv = abs(`v')
g d_event_neg`absv'_tr = campaigntime==`v' & campaign_treated == 1
}

g d_event_exact`0'_1tr = campaigntime==0 & campaign_treated == 1
g d_event_exact`0'_2tr = campaigntime==1 & campaign_treated == 1
g d_event_exact`0'_3tr = campaigntime==2 & campaign_treated == 1
g d_event_exact`0'_4tr = campaigntime==3 & campaign_treated == 1
g d_event_exact`0'_5tr = campaigntime==4 & campaign_treated == 1
g d_event_exact`0'_6tr = campaigntime==5 & campaign_treated == 1 if ///
province_name == "河南省" | province_name == "黑龙江省" | province_name == "广东省" | province_name == "湖北省"

forval v = 1/`maxbalancedeventtime' {
g d_event_pos`v'_tr = campaigntime2==`v' & campaign_treated == 1
}

sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin
gen t2=t^2
save event_10wk, replace

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_SO2 d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr, absorb(plant_name1 yweek) vce(cluster province_name)
}
eststo linear_plant_time_trend
outreg2 using tableS4_nt.tex, replace keep(d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)


***** table event_nt
use campaign_all_10wk_match_nt, replace
loc minbalancedeventtime = -10
loc maxbalancedeventtime = 10

forval v = `minbalancedeventtime'/-1 {
loc absv = abs(`v')
g d_event_neg`absv'_tr = campaigntime==`v' & campaign_treated == 1
}

g d_event_exact`0'_1tr = campaigntime==0 & campaign_treated == 1
g d_event_exact`0'_2tr = campaigntime==1 & campaign_treated == 1
g d_event_exact`0'_3tr = campaigntime==2 & campaign_treated == 1
g d_event_exact`0'_4tr = campaigntime==3 & campaign_treated == 1
g d_event_exact`0'_5tr = campaigntime==4 & campaign_treated == 1
g d_event_exact`0'_6tr = campaigntime==5 & campaign_treated == 1 if province_name == "河南省" | province_name == "黑龙江省" | province_name == "广东省" | province_name == "湖北省"

forval v = 1/`maxbalancedeventtime' {
g d_event_pos`v'_tr = campaigntime2==`v' & campaign_treated == 1
}

sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin
gen t2=t^2
save event_10wk, replace

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_SO2 d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr [pweight=_webal], absorb(plant_name1 yweek) vce(cluster province_name)
} 
eststo linear_plant_time_trend
outreg2 using tableS4_nt.tex, append keep(d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)

******* table event_all
use campaign_all_10wk, replace
loc minbalancedeventtime = -10
loc maxbalancedeventtime = 10

forval v = `minbalancedeventtime'/-1 {
loc absv = abs(`v')
g d_event_neg`absv'_tr = campaigntime==`v' & campaign_treated == 1
}

g d_event_exact`0'_1tr = campaigntime==0 & campaign_treated == 1
g d_event_exact`0'_2tr = campaigntime==1 & campaign_treated == 1
g d_event_exact`0'_3tr = campaigntime==2 & campaign_treated == 1
g d_event_exact`0'_4tr = campaigntime==3 & campaign_treated == 1
g d_event_exact`0'_5tr = campaigntime==4 & campaign_treated == 1
g d_event_exact`0'_6tr = campaigntime==5 & campaign_treated == 1 if ///
province_name == "河南省" | province_name == "黑龙江省" | province_name == "广东省" | province_name == "湖北省"

forval v = 1/`maxbalancedeventtime' {
g d_event_pos`v'_tr = campaigntime2==`v' & campaign_treated == 1
}

sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin
gen t2=t^2
save event_10wk, replace

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_SO2 d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr, absorb(plant_name1 yweek) vce(cluster province_name)
}
eststo linear_plant_time_trend
outreg2 using tableS4_all.tex, replace keep(d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)

use campaign_all_10wk_match, replace
loc minbalancedeventtime = -10
loc maxbalancedeventtime = 10

forval v = `minbalancedeventtime'/-1 {
loc absv = abs(`v')
g d_event_neg`absv'_tr = campaigntime==`v' & campaign_treated == 1
}

g d_event_exact`0'_1tr = campaigntime==0 & campaign_treated == 1
g d_event_exact`0'_2tr = campaigntime==1 & campaign_treated == 1
g d_event_exact`0'_3tr = campaigntime==2 & campaign_treated == 1
g d_event_exact`0'_4tr = campaigntime==3 & campaign_treated == 1
g d_event_exact`0'_5tr = campaigntime==4 & campaign_treated == 1
g d_event_exact`0'_6tr = campaigntime==5 & campaign_treated == 1 if province_name == "河南省" | province_name == "黑龙江省" | province_name == "广东省" | province_name == "湖北省"

forval v = 1/`maxbalancedeventtime' {
g d_event_pos`v'_tr = campaigntime2==`v' & campaign_treated == 1
}

sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin
gen t2=t^2
save event_10wk, replace

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_SO2 d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr [pweight=_webal], absorb(plant_name1 yweek) vce(cluster province_name)
}
eststo linear_plant_time_trend
outreg2 using tableS4_all.tex, append keep(d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)


****** table event_at
use campaign_all_10wk_at, replace
loc minbalancedeventtime = -10
loc maxbalancedeventtime = 10

forval v = `minbalancedeventtime'/-1 {
loc absv = abs(`v')
g d_event_neg`absv'_tr = campaigntime==`v' & campaign_treated == 1
}

g d_event_exact`0'_1tr = campaigntime==0 & campaign_treated == 1
g d_event_exact`0'_2tr = campaigntime==1 & campaign_treated == 1
g d_event_exact`0'_3tr = campaigntime==2 & campaign_treated == 1
g d_event_exact`0'_4tr = campaigntime==3 & campaign_treated == 1
g d_event_exact`0'_5tr = campaigntime==4 & campaign_treated == 1
g d_event_exact`0'_6tr = campaigntime==5 & campaign_treated == 1 if ///
province_name == "河南省" | province_name == "黑龙江省" | province_name == "广东省" | province_name == "湖北省"

forval v = 1/`maxbalancedeventtime' {
g d_event_pos`v'_tr = campaigntime2==`v' & campaign_treated == 1
}

sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin
gen t2=t^2
save event_10wk, replace

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_SO2 d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr, absorb(plant_name1 yweek) vce(cluster province_name)
}
eststo linear_plant_time_trend
outreg2 using tableS4_at.tex, replace keep(d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)

use campaign_all_10wk_match_at, replace
loc minbalancedeventtime = -10
loc maxbalancedeventtime = 10

forval v = `minbalancedeventtime'/-1 {
loc absv = abs(`v')
g d_event_neg`absv'_tr = campaigntime==`v' & campaign_treated == 1
}

g d_event_exact`0'_1tr = campaigntime==0 & campaign_treated == 1
g d_event_exact`0'_2tr = campaigntime==1 & campaign_treated == 1
g d_event_exact`0'_3tr = campaigntime==2 & campaign_treated == 1
g d_event_exact`0'_4tr = campaigntime==3 & campaign_treated == 1
g d_event_exact`0'_5tr = campaigntime==4 & campaign_treated == 1
g d_event_exact`0'_6tr = campaigntime==5 & campaign_treated == 1 if province_name == "河南省" | province_name == "黑龙江省" | province_name == "广东省" | province_name == "湖北省"

forval v = 1/`maxbalancedeventtime' {
g d_event_pos`v'_tr = campaigntime2==`v' & campaign_treated == 1
}

sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin
gen t2=t^2
save event_10wk, replace

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_SO2 d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr [pweight=_webal], absorb(plant_name1 yweek) vce(cluster province_name)
}
eststo linear_plant_time_trend
outreg2 using tableS4_at.tex, append keep(d_event_neg10_tr-d_event_neg6_tr d_event_neg4_tr-d_event_pos10_tr) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)




************** tableS5
****** table 5_new appendix

****** table 5_csdid
*** all
use campaign_est_baseline, replace
gen nox_scrubber = 0
replace nox_scrubber  = 1 if totalcap_nox_scrubber>0
keep if nox_scrubber == 0

csdid  log_concentration_NOX, ivar(plant_name1) time(yweek) gvar(baseline) method(dripw) cluster(city_name1)

estat cevent, window(1 4) estore(announcement)
*** ATT for events between -4 to -1 week
estat cevent, window(5 9) estore(onsite)
*** ATT for events between 0 to 4 week
*estat cevent, window(10 19) estore(post)
estat cevent, window(10 14) estore(rebound1)
estat cevent, window(15 19) estore(rebound2)

esttab announcement onsite rebound1 rebound2 using tableS5.tex, se replace


*** central soe
use campaign_est_baseline, replace
gen nox_scrubber = 0
replace nox_scrubber  = 1 if totalcap_nox_scrubber>0
keep if nox_scrubber == 0
gen central_soe = 0
replace central_soe = 1 if oversightlevel == "country-level" & soe == 1

keep if  central_soe == 1
csdid  log_concentration_NOX, ivar(plant_name1) time(yweek) gvar(baseline) method(dripw) cluster(city_name1)

estat cevent, window(1 4) estore(announcement)
*** ATT for events between -4 to -1 week
estat cevent, window(5 9) estore(onsite)
*** ATT for events between 0 to 4 week
*estat cevent, window(10 19) estore(post)
estat cevent, window(10 14) estore(rebound1)
estat cevent, window(15 19) estore(rebound2)

esttab announcement onsite rebound1 rebound2 using tableS5.tex, se append

***** city or below soe
use campaign_est_baseline, replace
gen nox_scrubber = 0
replace nox_scrubber  = 1 if totalcap_nox_scrubber>0
keep if nox_scrubber == 0
gen lower_soe = 0
replace lower_soe = 1 if (oversightlevel == "county-level" | oversightlevel == "city-level") & soe == 1

keep if  lower_soe == 1
csdid  log_concentration_NOX, ivar(plant_name1) time(yweek) gvar(baseline) method(dripw) cluster(city_name1)

estat cevent, window(1 4) estore(announcement)
*** ATT for events between -4 to -1 week
estat cevent, window(5 9) estore(onsite)
*** ATT for events between 0 to 4 week
*estat cevent, window(10 19) estore(post)
estat cevent, window(10 14) estore(rebound1)
estat cevent, window(15 19) estore(rebound2)

esttab announcement onsite rebound1 rebound2 using tableS5.tex, se append


************ table S6
use campaign_all_10wk_match_nt, replace
keep if nox_scrubber == 0

gen campaign_prepare = campaigntime >= -4 & campaigntime <= -1 & campaign_treated == 1
gen campaign_onsite = campaigntime >= 0 & campaigntime2 <= 0 & campaign_treated == 1
gen campaign_post = campaigntime2 >= 1 & campaign_treated == 1
gen campaign_rebound1 = campaigntime2 >= 1 & campaigntime2 < 6 & campaign_treated == 1
gen campaign_rebound2 = campaigntime2 >= 6 & campaigntime2 <= 10 & campaign_treated == 1
sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin + 1

gen campaign_post_NOX = campaign_post * so2_scrubber
gen campaign_onsite_NOX = campaign_onsite * so2_scrubber
gen campaign_rebound1_NOX = campaign_rebound1 * so2_scrubber
gen campaign_rebound2_NOX = campaign_rebound2 * so2_scrubber

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_NOX campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_NOX campaign_rebound1_NOX campaign_rebound2_NOX [pweight=_webal], absorb(plant_name1 yweek) vce(cluster city_name)
}
eststo linear_plant_time_trend
outreg2 using tableS6.tex, replace keep(campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_NOX campaign_rebound1_NOX campaign_rebound2_NOX) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)


use campaign_all_10wk_match_nt, replace
keep if nox_scrubber == 0
keep if central_soe == 1

gen campaign_prepare = campaigntime >= -4 & campaigntime <= -1 & campaign_treated == 1
gen campaign_onsite = campaigntime >= 0 & campaigntime2 <= 0 & campaign_treated == 1
gen campaign_post = campaigntime2 >= 1 & campaign_treated == 1
gen campaign_rebound1 = campaigntime2 >= 1 & campaigntime2 < 6 & campaign_treated == 1
gen campaign_rebound2 = campaigntime2 >= 6 & campaigntime2 <= 10 & campaign_treated == 1
sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin + 1

gen campaign_post_NOX = campaign_post * so2_scrubber
gen campaign_onsite_NOX = campaign_onsite * so2_scrubber
gen campaign_rebound1_NOX = campaign_rebound1 * so2_scrubber
gen campaign_rebound2_NOX = campaign_rebound2 * so2_scrubber

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_NOX campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_NOX campaign_rebound1_NOX campaign_rebound2_NOX [pweight=_webal], absorb(plant_name1 yweek) vce(cluster city_name)
}
eststo linear_plant_time_trend
outreg2 using tableS6.tex, append keep(campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_NOX campaign_rebound1_NOX campaign_rebound2_NOX) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)


use campaign_all_10wk_match_nt, replace
keep if nox_scrubber == 0
keep if state_lower == 1

gen campaign_prepare = campaigntime >= -4 & campaigntime <= -1 & campaign_treated == 1
gen campaign_onsite = campaigntime >= 0 & campaigntime2 <= 0 & campaign_treated == 1
gen campaign_post = campaigntime2 >= 1 & campaign_treated == 1
gen campaign_rebound1 = campaigntime2 >= 1 & campaigntime2 < 6 & campaign_treated == 1
gen campaign_rebound2 = campaigntime2 >= 6 & campaigntime2 <= 10 & campaign_treated == 1
sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin + 1

gen campaign_post_NOX = campaign_post * so2_scrubber
gen campaign_onsite_NOX = campaign_onsite * so2_scrubber
gen campaign_rebound1_NOX = campaign_rebound1 * so2_scrubber
gen campaign_rebound2_NOX = campaign_rebound2 * so2_scrubber

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_NOX campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_NOX campaign_rebound1_NOX campaign_rebound2_NOX [pweight=_webal], absorb(plant_name1 yweek) vce(cluster city_name)
}
eststo linear_plant_time_trend
outreg2 using tableS6.tex, append keep(campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_NOX campaign_rebound1_NOX campaign_rebound2_NOX) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)


************* code for table S7 ********* city standard error
use campaign_all_10wk_match_nt, replace
keep if nox_scrubber == 0
gen campaign_prepare = campaigntime >= -4 & campaigntime <= -1 & campaign_treated == 1
gen campaign_onsite = campaigntime >= 0 & campaigntime2 <= 0 & campaign_treated == 1
gen campaign_post = campaigntime2 >= 1 & campaign_treated == 1
gen campaign_rebound1 = campaigntime2 >= 1 & campaigntime2 < 6 & campaign_treated == 1
gen campaign_rebound2 = campaigntime2 >= 6 & campaigntime2 <= 10 & campaign_treated == 1
sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin + 1

gen campaign_post_so2 = campaign_post * so2_scrubber
gen campaign_onsite_so2 = campaign_onsite * so2_scrubber
gen campaign_rebound1_so2 = campaign_rebound1 * so2_scrubber
gen campaign_rebound2_so2 = campaign_rebound2 * so2_scrubber

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_NOX campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_so2 campaign_rebound1_so2 campaign_rebound2_so2 [pweight=_webal], absorb(plant_name1 yweek) vce(cluster city_name)
}
eststo linear_plant_time_trend
outreg2 using tableS7.tex, replace keep(campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_so2 campaign_rebound1_so2 campaign_rebound2_so2) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)

use campaign_all_10wk_match_nt, replace
keep if nox_scrubber == 0
keep if less_than_50mw == 1
gen campaign_prepare = campaigntime >= -4 & campaigntime <= -1 & campaign_treated == 1
gen campaign_onsite = campaigntime >= 0 & campaigntime2 <= 0 & campaign_treated == 1
gen campaign_post = campaigntime2 >= 1 & campaign_treated == 1
gen campaign_rebound1 = campaigntime2 >= 1 & campaigntime2 < 6 & campaign_treated == 1
gen campaign_rebound2 = campaigntime2 >= 6 & campaigntime2 <= 10 & campaign_treated == 1
sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin + 1

gen campaign_post_so2 = campaign_post * so2_scrubber
gen campaign_onsite_so2 = campaign_onsite * so2_scrubber
gen campaign_rebound1_so2 = campaign_rebound1 * so2_scrubber
gen campaign_rebound2_so2 = campaign_rebound2 * so2_scrubber

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_NOX campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_so2 campaign_rebound1_so2 campaign_rebound2_so2 [pweight=_webal], absorb(plant_name1 yweek) vce(cluster city_name)
}
eststo linear_plant_time_trend
outreg2 using tableS7.tex, append keep(campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_so2 campaign_rebound1_so2 campaign_rebound2_so2) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)


use campaign_all_10wk_match_nt, replace
keep if nox_scrubber == 0
keep if over_50mw_less_500mw == 1
gen campaign_prepare = campaigntime >= -4 & campaigntime <= -1 & campaign_treated == 1
gen campaign_onsite = campaigntime >= 0 & campaigntime2 <= 0 & campaign_treated == 1
gen campaign_post = campaigntime2 >= 1 & campaign_treated == 1
gen campaign_rebound1 = campaigntime2 >= 1 & campaigntime2 < 6 & campaign_treated == 1
gen campaign_rebound2 = campaigntime2 >= 6 & campaigntime2 <= 10 & campaign_treated == 1
sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin + 1

gen campaign_post_so2 = campaign_post * so2_scrubber
gen campaign_onsite_so2 = campaign_onsite * so2_scrubber
gen campaign_rebound1_so2 = campaign_rebound1 * so2_scrubber
gen campaign_rebound2_so2 = campaign_rebound2 * so2_scrubber

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_NOX campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_so2 campaign_rebound1_so2 campaign_rebound2_so2 [pweight=_webal], absorb(plant_name1 yweek) vce(cluster city_name)
}
eststo linear_plant_time_trend
outreg2 using tableS7.tex, append keep(campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_so2 campaign_rebound1_so2 campaign_rebound2_so2) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)


use campaign_all_10wk_match_nt, replace
keep if nox_scrubber == 0
keep if over_500mw == 1
gen campaign_prepare = campaigntime >= -4 & campaigntime <= -1 & campaign_treated == 1
gen campaign_onsite = campaigntime >= 0 & campaigntime2 <= 0 & campaign_treated == 1
gen campaign_post = campaigntime2 >= 1 & campaign_treated == 1
gen campaign_rebound1 = campaigntime2 >= 1 & campaigntime2 < 6 & campaign_treated == 1
gen campaign_rebound2 = campaigntime2 >= 6 & campaigntime2 <= 10 & campaign_treated == 1
sort plant_name yweek
by plant_name: egen weekmin= min(yweek)
gen t= yweek - weekmin + 1

gen campaign_post_so2 = campaign_post * so2_scrubber
gen campaign_onsite_so2 = campaign_onsite * so2_scrubber
gen campaign_rebound1_so2 = campaign_rebound1 * so2_scrubber
gen campaign_rebound2_so2 = campaign_rebound2 * so2_scrubber

forval o=0/2 {
eststo y`o':  reghdfe log_concentration_NOX campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_so2 campaign_rebound1_so2 campaign_rebound2_so2 [pweight=_webal], absorb(plant_name1 yweek) vce(cluster city_name)
}
eststo linear_plant_time_trend
outreg2 using tableS7.tex, append keep(campaign_prepare campaign_onsite campaign_rebound1 campaign_rebound2 ///
campaign_onsite_so2 campaign_rebound1_so2 campaign_rebound2_so2) ///
nocons addtext(Plant FE, Yes, Year FE, Yes, Week FE, Yes) dec(3)
